package com.ioioioio.service.impl;

import com.ioioioio.dao.UserDao;
import com.ioioioio.pojo.Resume;
import com.ioioioio.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

/**
 * @Package: com.ioioioio.service.impl
 * @Author: Dot
 * @Description:
 * @Date: 2020/10/15 11:04
 * @Version: 1.0
 */
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserDao userDao;

    @Override
    public void removeResume(Long id) {
        userDao.deleteById(id);
    }

    @Override
    public Resume addResume(Resume resume) {
        if(null != resume){
            return userDao.save(resume);
        }
        return null;
    }

    @Override
    public Resume editResume(Resume resume) {
        if(null != resume){
            return userDao.save(resume);
        }
        return null;
    }

    @Override
    public Resume userInfoCheck(String name, String phone) {
        Resume resume = new Resume();
        resume.setName(name);
        resume.setPhone(phone);
        Optional<Resume> one = userDao.findOne(Example.of(resume));
        return one.isPresent() ? one.get() : null;
    }

    @Override
    public List<Resume> allAccount() {
        return userDao.findAll();
    }
}
